﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using prohomework.Models.SqlClient;
using prohomework.Models;
using System.Data.SqlClient;
using System.Data;
using System.Web.Mvc;
namespace prohomework.Controllers
{
    public class TeacherControllerBL:SqlBaseDBHandler<prohomework.Models.homeworkIndex>
    {
        public TeacherControllerBL() : base(DBConnection.connectionstring)
        {
            CmdType = CommandType.Text;
        }

        protected override void AddParametersFromModel(homeworkIndex model)
        {
      //      parameters.addwithvalue("@schoolcode", model.schoolcode);
     //       parameters.addwithvalue("@schoolname", model.schoolname);
        }

        protected override homeworkIndex AssembleFromReader(SqlDataReader reader)
        {
            if (reader.Read())
            {
                //      homeworkIndex sm = new homeworkIndex();
                //     sm.courseID = reader["id"].ToString();
                //        sm.coursename = reader["批阅名称"].ToString();
                //     return sm;
                return null;
            }
            else
                return null;
        }

        public override int Create(homeworkIndex dbobj)
        {
            CommandText = "sdfsd";
            AddParametersFromModel(dbobj);
            int result;
            return Executant.Act(out result);
        }

        public override bool Update(homeworkIndex dbobj)
        {
        //    CommandText = sdas;
            AddParametersFromModel(dbobj);
            int result;
            Executant.Act(out result);
            return result >= 1;
        }

        public override bool Delete(homeworkIndex dbobj)
        {
      //      CommandText = sp_school_Delete;
          //  Parameters.AddWithValue("@ID", dbobj.ID);
            int result;
            Executant.Act(out result);
            return result >= 1;
        }

        protected override homeworkIndex GetModel(int id)
        {
            CommandText = "ssd";
            Parameters.AddWithValue("@ID", id);
            SqlDataReader reader;
            Executant.Act(out reader);
            homeworkIndex model = AssembleFromReader(reader);
            CloseReader(reader);
            return model;
        }


        public List<SelectListItem> GetAll(string sql, string value, string text)
        {
            CommandText = sql;
            SqlDataReader reader;
            this.Executant.Act(out reader);
            List<SelectListItem> models = new List<SelectListItem>();
         //   homeworkIndex model;
            while (reader.Read())
            {
                SelectListItem sm = new SelectListItem();
                sm.Value = reader[value].ToString();
                sm.Text = reader[text].ToString();
                models.Add(sm);
            }

            this.CloseReader(reader);
            return models;
        }



    }
}